/*
卷积神经网络主类头文件
定义完整的CNN架构和训练流程
支持多层卷积、池化和全连接组合
*/
#ifndef CONV_NEURAL_NETWORK_H
#define CONV_NEURAL_NETWORK_H

#include "Macros.h"
#ifdef USE_USER_DEFINED_TENSOR 
    #undef USE_EIGEN_TENSOR
    #include "Tensor.h"
#endif
#ifdef USE_EIGEN_TENSOR
    #undef USE_USER_DEFINED_TENSOR
    #include <Eigen/Core>
    #include <Eigen/Dense>
#endif
#include "Layer.h"
#include "ConvLayer.h"
#include "PoolingLayer.h"
#include "FullConnectedLayer.h"
#include "LayerManager.h"
#include <string>
#include <vector>
#include <memory>
#include "jsonParser.h"

#ifdef USE_EIGEN_TENSOR
// Enable Eigen parallelization
#define EIGEN_USE_THREADS
#endif

using namespace std;
#ifdef USE_EIGEN_TENSOR
using namespace Eigen;
#endif
#ifdef USE_USER_DEFINED_TENSOR
using namespace UserDefinedTensor;
#endif

class ConvNeuralNetwork {
public:
    ConvNeuralNetwork(const string& configFile = "../config/config.json");
    ~ConvNeuralNetwork();
    void forward(const Tensor<double, 3>& input);
    void backward(const Tensor<double, 1>& target);
    void train(const Tensor<double, 3>& input, const Tensor<double, 1>& target, const int batchSize, const int epochs, const double learningRate, const double momentum);
    void predict(const Tensor<double, 3>& input, Tensor<double, 1>& output);
    void update(double learningRate, double momentum);
    void saveModel(const string& modelFile);
    void loadModel(const string& modelFile);
    void getModel(const string& modelFile);
    void setModel(const string& modelFile);
    void print();
    void printLayer(int layerIndex);

private:
    void init(const string& configFile);
    void init(const string& configFile, const string& modelFile);
    void init(const string& configFile, const string& modelFile, const string& modelFile2);
};

#endif // CONV_NEURAL_NETWORK_H